package com.xy.breakfast.service;

import com.xy.breakfast.entity.Clients;
import com.xy.breakfast.mapper.ClientsMapper;
import org.apache.ibatis.annotations.Insert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClientsService implements ClientsMapper{
    @Autowired
    ClientsMapper clientsMapper;


    //注册功能
    public String registration(Clients clients){
        if(clients.getEmail().trim().length()==0){
            return "邮箱不能为空";
        }
        if(clients.getEmail().indexOf("@")==-1){
            return "邮箱格式不对";
        }

        //查找邮箱存在
        if(clientsMapper.findByEmail(clients.getEmail())!=null){
            return "用户已经存在";
        }

        if(clients.getPassword().trim().length()<6){
            return "密码长度必须小于6";
        }

        this.save(clients);

        return "ok";
    }
    @Override
    @Cacheable //缓存：只取1次，第二次从缓存中取数据
    public Clients getById(int id) {
        return clientsMapper.getById(id);
    }

    @Override
    public void save(Clients t) {
        this.clientsMapper.save(t);
    }

    @Override
    public Clients findByEmail(String email) {
        return this.clientsMapper.findByEmail(email);
    }

    @Override
    public void deleteById(int id) {

    }

    @Override
    public void update(Clients t) {

    }

    @Override
    public List<Clients> getAll() {
        return null;
    }

    @Override
    public List<Clients> getPage(int start, int end) {
        return null;
    }
}
